#!/bin/bash
# - test_item
# - num_type

# SPDX-License-Identifier: MulanPSL-2.0+
# Copyright (c) 2022 Huawei Technologies Co., Ltd. All rights reserved.
. $LKP_SRC/lib/env.sh
. $LKP_SRC/lib/reproduce-log.sh
. $LKP_SRC/lib/upload.sh
. $LKP_SRC/lib/perf_file_system.sh


yum -y install wget gcc gcc-c++  make numactl gcc-gfortran libnsl tar
mk_fs_mount "/home"


: "${test_item:=rate}"
: "${num_type:=int}"

cd /home
wget https://api.compass-ci.openeuler.org:20009/os/install/performance_tools/cpu2006-1.2.iso
wget https://api.compass-ci.openeuler.org:20009/os/install/performance_tools/speccpu-2006.tar.gz

[ -f speccpu-2006.tar.gz ] && tar xvf speccpu-2006.tar.gz
[ -d /home/speccpu2006 ] && {
	cd /home/speccpu2006
	./speccpu2006-install.sh
}

[ $? == 0 ] || exit

case $test_item in
rate)
	[[ $num_type == int ]] && {
		echo 'runspec -c $cfg --rate `nproc` -n 3 --noreportable -o all int' >> /home/speccpu2006/cpu2006-test.sh
	}
	[[ $num_type != int ]] && {
		echo 'runspec -c $cfg --rate `nproc` -n 3 --noreportable -o all fp' >> /home/speccpu2006/cpu2006-test.sh
	}
	;;
speed)
	[[ $num_type == int ]] && {
		echo 'runspec -c $cfg --speed -n 3 --noreportable -o all int' >> /home/speccpu2006/cpu2006-test.sh
	}
	[[ $num_type != int ]] && {
		echo 'runspec -c $cfg --speed -n 3 --noreportable -o all fp' >> /home/speccpu2006/cpu2006-test.sh
	}
	;;
esac

cat >> /home/speccpu2006/cpu2006-test.sh <<-EOF
sysctl -w vm.drop_caches=3
sleep 300

# clean some trash after build and run
rm -rf ./benchspec/CPU2006/*/run/*
EOF
log_cmd use_benchmark_env ./cpu2006-test.sh
upload_files -t results /home/cpu2006-1.2/result/*

if [ $? == 0 ];then
	[ -d '/home/cpu2006-1.2/result' ] && cat /home/cpu2006-1.2/result/*.txt
else
  exit
fi
